//
//  TTScopeView.m
//  TaoTuo
//
//  Created by admin on 2019/8/21.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTScopeView.h"

@interface TTScopeView ()

@property (nonatomic, strong) UILabel *titleLabel;  // 标题
@property (nonatomic, strong) UIView *lineView;     // 线
@property (nonatomic, copy) NSString *title;

@property (nonatomic, assign) BOOL hiddenTF;

@end

@implementation TTScopeView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title hiddenTextField:(BOOL)hiddenTextField
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.hiddenTF = hiddenTextField;
        self.title = title;
        
        [self setupSubviews];
        
    }
    return self;
}

- (void)resetView
{
    self.minTF.text = @"";
    self.maxTF.text = @"";
}

- (void)setMinStr:(NSString *)minStr maxStr:(NSString *)maxStr
{
    self.minTF.text = minStr;
    self.maxTF.text = maxStr;
}

- (void)setMinTFLeftSpace:(CGFloat)minTFLeftSpace
{
    _minTFLeftSpace = minTFLeftSpace;
    
    [self.minTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(minTFLeftSpace);
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(90);
    }];
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.minTF.mas_right).mas_offset(10);
        make.centerY.equalTo(self);
        make.width.equalTo(@5);
        make.height.equalTo(@1);
    }];
    
    [self.maxTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView.mas_right).mas_offset(10);
        make.top.bottom.equalTo(self.minTF);
        make.width.mas_equalTo(90);
    }];
    
}

- (void)setupSubviews
{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.height.equalTo(self);
        make.width.mas_equalTo(80 * kScale);
    }];
    
    if (!self.hiddenTF) {
        
        [self.minTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right);
            make.top.mas_equalTo(5);
            make.bottom.mas_equalTo(-5);
            make.width.mas_equalTo(90);
        }];
        
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.minTF.mas_right).mas_offset(10);
            make.centerY.equalTo(self);
            make.width.equalTo(@5);
            make.height.equalTo(@1);
        }];
        
        [self.maxTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lineView.mas_right).mas_offset(10);
            make.top.bottom.equalTo(self.minTF);
            make.width.mas_equalTo(90);
        }];
        
    }
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:16];
        _titleLabel.text = self.title;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UITextField *)minTF
{
    if (!_minTF) {
        _minTF = [[UITextField alloc] init];
        _minTF.backgroundColor = UIColorHex(F0F4F7);
        _minTF.keyboardType = UIKeyboardTypeDecimalPad;
        _minTF.textAlignment = NSTextAlignmentCenter;
        _minTF.textColor = UIColorHex(333333);
        _minTF.layer.cornerRadius = 5;
        _minTF.font = [UIFont systemFontOfSize:15];
        [self addSubview:_minTF];
    }
    return _minTF;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = UIColorHex(666666);
        [self addSubview:_lineView];
    }
    return _lineView;
}


- (UITextField *)maxTF
{
    if (!_maxTF) {
        _maxTF = [[UITextField alloc] init];
        _maxTF.backgroundColor = UIColorHex(F0F4F7);
        _maxTF.keyboardType = UIKeyboardTypeDecimalPad;
        _maxTF.textAlignment = NSTextAlignmentCenter;
        _maxTF.textColor = UIColorHex(333333);
        _maxTF.layer.cornerRadius = 5;
        _maxTF.font = [UIFont systemFontOfSize:15];
        [self addSubview:_maxTF];
    }
    return _maxTF;
}

@end
